part of '../controller.dart';

const _kYookassaApiPaymentKey = 'object';

const _kYookassaApiSucceededPaymentNotificationTypeValue = 'payment.succeeded';
const _kYookassaApiCanceledPaymentNotificationTypeValue = 'payment.canceled';
const _kYookassaApiSucceededRefundNotificationTypeValue = 'refund.succeeded';

class _YookassaApiPaymentNotificationDto extends Equatable
    implements _NotificationDto {
  const _YookassaApiPaymentNotificationDto._internal({
    required this.paymentDto,
  });

  final YookassaApiPaymentDto paymentDto;

  @override
  List<Object?> get props {
    return [
      paymentDto,
    ];
  }

  factory _YookassaApiPaymentNotificationDto.fromJson(Map<String, dynamic> json) {
    final paymentJson = json[_kYookassaApiPaymentKey];
    final paymentDto = YookassaApiPaymentDtoFactory().fromJson(paymentJson);

    return _YookassaApiPaymentNotificationDto._internal(
      paymentDto: paymentDto,
    );
  }

  @override
  YookassaApiPaymentNotification toEntity() {
    final payment = paymentDto.toEntity();

    return YookassaApiPaymentNotification(
      payment: payment,
    );
  }
}
